package com.example.mingyue.config;

import com.example.mingyue.constant.MqConstant;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * rabbitmq初始化交换机、新增删除消息队列
 */
@Configuration
public class MqExchangeConfig {

    /**
     * 交换机
     * @return
     */
    @Bean
    public TopicExchange topicExchange(){

        return new TopicExchange(MqConstant.MINGYUE_EXCHANGE,true,false);
    }

    /**
     * 添加队列
     * @return
     */
    @Bean
    public Queue insertQueue(){
        return new Queue(MqConstant.MINGYUE_INSERT_QUEUE,true);
    }
    /**
     * 删除队列
     * @return
     */
    @Bean
    public Queue deleteQueue(){
        return new Queue(MqConstant.MINGYUE_DELETE_QUEUE,true);
    }
    /**
     * 绑定添加队列
     * @return
     */
    @Bean
    public Binding insertQueueBinding(){
        return BindingBuilder.bind(insertQueue()).to(topicExchange()).with(MqConstant.MINGYUE_INSERT_KEY);
    }
    /**
     * 绑定删除队列
     * @return
     */
    @Bean
    public Binding deleteQueueBinding(){
        return BindingBuilder.bind(deleteQueue()).to(topicExchange()).with(MqConstant.MINGYUE_DELETE_KEY);
    }


    /**
     * 添加帖子队列
     * @return
     */
    @Bean
    public Queue insertPostQueue(){
        return new Queue(MqConstant.MINGYUE_INSERTPOST_QUEUE,true);
    }
    /**
     * 删除帖子队列
     * @return
     */
    @Bean
    public Queue deletePostQueue(){
        return new Queue(MqConstant.MINGYUE_DELETEPOST_QUEUE,true);
    }
    /**
     * 绑定各自的队列
     */
    @Bean
    public Binding insertPostQueueBinding(){
        return BindingBuilder.bind(insertPostQueue()).to(topicExchange()).with(MqConstant.MINGYUE_INSERTPOST_KEY);
    }
    @Bean
    public Binding deletePostQueueBinding(){
        return BindingBuilder.bind(deletePostQueue()).to(topicExchange()).with(MqConstant.MINGYUE_DELETEPOST_KEY);
    }



}
